Skip to content

Fix: Surface destructive schema changes on forward-only models during dev plans (#5719)#5732

Closed
brucearctor wants to merge 2 commits into
SQLMesh:mainfrom
brucearctor:fix/destructive-schema-change-dev-plan
Closed

Fix: Surface destructive schema changes on forward-only models during dev plans (#5719)#5732
brucearctor wants to merge 2 commits into
SQLMesh:mainfrom
brucearctor:fix/destructive-schema-change-dev-plan

Conversation

@brucearctor
Copy link
Copy Markdown

Summary

Fixes #5719. Destructive schema changes on forward-only models are now surfaced at plan-build time during dev plans (sqlmesh plan dev), not just prod plans.

Problem

When a forward-only model has columns removed or types narrowed, sqlmesh plan dev and PR checks would succeed, but the production deployment would fail with a DestructiveChangeError during MigrateSchemasStage. This left the production environment in an unfinalized state.

Root Cause

PlanBuilder._check_destructive_additive_changes already checked for destructive schema changes at plan-build time (regardless of is_dev), but only for directly modified snapshots. Indirectly modified forward-only models (e.g., downstream models inheriting schema changes from an upstream dependency) were not checked. The evaluator-level check in MigrateSchemasStage catches these for prod, but that stage is skipped for dev plans.

Changes

sqlmesh/core/plan/builder.py

  • Extract schema diffing into reusable _check_schema_change helper method
  • Pass indirectly_modified mapping to _check_destructive_additive_changes
  • Add a second loop to check indirectly modified forward-only snapshots for destructive/additive schema changes

tests/core/test_plan.py

Add 5 new tests for is_dev=True scenarios:

  • test_forward_only_destructive_change_dev_plan — ERROR mode raises PlanError
  • test_forward_only_destructive_change_dev_plan_warn — WARN mode logs warning
  • test_forward_only_destructive_change_dev_plan_allow — ALLOW mode passes silently
  • test_forward_only_indirect_destructive_change_dev_plan — indirect modification path exercised
  • test_forward_only_flag_destructive_change_dev_plan--forward-only flag with dev plan

Test Results

All 27 forward-only/destructive tests pass (5 new + 22 existing), zero regressions.

… dev plans (SQLMesh#5719)

Extend _check_destructive_additive_changes in PlanBuilder to also inspect
indirectly modified forward-only snapshots for destructive/additive schema
changes. Previously, only directly modified snapshots were checked, and the
evaluator-level check (MigrateSchemasStage) is skipped for dev plans.

Changes:
- Refactor schema diffing into reusable _check_schema_change helper
- Pass indirectly_modified mapping to _check_destructive_additive_changes
- Add loop to check indirectly modified forward-only snapshots
- Add 5 new tests for is_dev=True scenarios (ERROR/WARN/ALLOW modes,
  indirect modification, --forward-only flag)
@StuffbyYuki
Copy link
Copy Markdown
Collaborator

@brucearctor it looks like the direct-modification case already raises PlanError on current main. Could you maybe clarify what version/scenario you reproduced, and update the PR description to state that the net-new behavior is the indirect-modification loop (plus the _check_schema_change refactor).

@brucearctor
Copy link
Copy Markdown
Author

This PR was opened months ago.

Way too long has passed for me to recall.

Too stale for me to worry about - it was solving someone else's reported bug -- i was trying to get involved with supporting this project.

@brucearctor
Copy link
Copy Markdown
Author

Closing, as i thats too long to maintain context

@brucearctor brucearctor closed this Jun 6, 2026
@StuffbyYuki
Copy link
Copy Markdown
Collaborator

@brucearctor Apologize we didn't pick it up sooner. The TSC was formed and starting to be active in the last couple of weeks after sqlmesh had been donated to Linux Foundation. We'll be more active going forward though

@brucearctor
Copy link
Copy Markdown
Author

All good. Apologies not needed. I just cant recall the status as was someone else's issue. And given 3 months has passed since opening that PR, it seemed reasonable for me to consider sufficiently stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Destructive schema changes on forward-only models not surfaced until prod deploy

2 participants